import { prisma } from '../../../utils/prisma'
import { getUserIdOrThrow } from '../../../utils/guard'

export default eventHandler(async (event) => {
  const userId = getUserIdOrThrow(event)
  const id = Number(getRouterParam(event, 'id'))
  if (!Number.isFinite(id)) throw createError({ statusCode: 400, statusMessage: 'BAD_ID' })
  const exists = await prisma.activityTemplate.findFirst({ where: { id, userId } })
  if (!exists) throw createError({ statusCode: 404, statusMessage: 'NOT_FOUND' })
  await prisma.activityTemplate.delete({ where: { id } })
  return { ok: true }
})


